﻿using System.Data;
using ECM7.Migrator.Framework;
using ForeignKeyConstraint = ECM7.Migrator.Framework.ForeignKeyConstraint;

namespace music.domain.Migrations
{
	[Migration(9)]
	public class Migration009_Rates : Migration
	{
		public override void Apply()
		{
			Database.AddTable("Rates",
				new Column("UserId", DbType.Guid, ColumnProperty.PrimaryKey),
				new Column("SongId", DbType.Guid, ColumnProperty.PrimaryKey),
				new Column("IsNegative", DbType.Boolean, ColumnProperty.NotNull)
			);

			Database.AddForeignKey("FK_RatesUser", "Rates", "UserId", "Users", "Id", ForeignKeyConstraint.Cascade);
			Database.AddForeignKey("FK_RatesSong", "Rates", "SongId", "Songs", "Id", ForeignKeyConstraint.Cascade);
		}

		public override void Revert()
		{
			Database.RemoveConstraint("Rates", "FK_RatesSong");
			Database.RemoveConstraint("Rates", "FK_RatesUser");

			Database.RemoveTable("Rates");
		}
	}
}